import React, { Component } from 'react'

export default class Count extends Component {
    state = { count: 0 }
    add = () => {
        const { value } = this.selectedNum
        const { count } = this.state
        const sum = Number(value) + count
        this.setState({ count: sum })
    }
    reduce = () => {
        const { value } = this.selectedNum
        const { count } = this.state
        const sum = count - Number(value)
        this.setState({ count: sum })
    }
    render() {
        return (
            <div>
                <h2>sum = {this.state.count}</h2>
                <select ref={c => this.selectedNum = c}>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
                &nbsp;
                <button onClick={this.add}>+</button> &nbsp;
                <button onClick={this.reduce}>-</button>
            </div>
        )
    }
}
